﻿/*
NTerm: A .NET based terminal abstraction library
Copyright (C) 2011  Bryan Perris

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NTerm
{
    /// <summary>
    /// Defines a data structre representing a postion
    /// </summary>
    public struct Position
    {
        int x;
        int y;

        /// <summary>
        /// Creates an instance of a position
        /// </summary>
        /// <param name="x">The X position</param>
        /// <param name="y">The Y position</param>
        public Position(int x, int y)
        {
            this.x = x;
            this.y = y;
        }

        /// <summary>
        /// Gets the X position
        /// </summary>
        public int X
        {
            get { return x; }
            set { x = value; }
        }

        /// <summary>
        /// Gets the Y position
        /// </summary>
        public int Y
        {
            get { return y; }
            set { y = value; }
        }

        /// <summary>
        /// Determines whether this instance and another specified object, which has to be a type of Position, are the same value
        /// </summary>
        /// <param name="obj">The Position to compare this instance</param>
        /// <returns>true if obj is a Position and its value is the same as this instance; otherwise, false</returns>   
        public override bool Equals(object obj)
        {
            return x.Equals(((Position)obj).x) && y.Equals(((Position)obj).y);
        }

        /// <summary>
        /// Returns a hash code for this position
        /// </summary>
        /// <returns>A 32-bit signed integer hash code</returns>
        public override int GetHashCode()
        {
            return x ^ y;
        }

        /// <summary>
        /// Converts the position value of this instance to its equivalent string representation.
        /// </summary>
        /// <returns>Returns the string representation of the the value of this instance</returns>
        public override string ToString()
        {
            return "{" + x.ToString(System.Globalization.CultureInfo.CurrentCulture) + ", " + y.ToString(System.Globalization.CultureInfo.CurrentCulture) + "}";
        }

        /// <summary>
        /// Overriden
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool operator ==(Position a, Position b)
        {
            return a.Equals(b);
        }

        /// <summary>
        /// Overriden
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool operator !=(Position a, Position b)
        {
            return !(a == b);
        }
    }
}
